SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.DnnProduct_GetBanner
@BannerId int
as
select B.BannerId,
	   B.VendorId,
	   'ImageFile' = case when F.FileName is null then B.ImageFile else F.Folder + F.FileName end,
	   B.BannerName,
	   B.Impressions,
	   B.CPM,
	   B.Views,
	   B.ClickThroughs,
	   B.StartDate,
	   B.EndDate,
	   'CreatedByUser' = U.FirstName + ' ' + U.LastName,
	   B.CreatedDate,
	   B.BannerTypeId,
	   B.Description,
	   B.GroupName,
	   B.Criteria,
	   B.URL,        
	   B.Width,
	   B.Height,
	   B.ImageFile AS ImageFileRaw
from   dbo.DnnProduct_Banners B 
inner join dbo.DnnProduct_Vendors V ON B.VendorId = V.VendorId 
left outer join dbo.DnnProduct_Users U ON B.CreatedByUser = U.UserID
left outer join dbo.DnnProduct_Files F on B.ImageFile = 'FileId=' + convert(varchar,F.FileID)
where  B.BannerId = @BannerId

GO
